<?php

use Faker\Factory as Faker;
use App\Models\ItemManager;
use App\Repositories\ItemManagerRepository;

trait MakeItemManagerTrait
{
    /**
     * Create fake instance of ItemManager and save it in database
     *
     * @param array $itemManagerFields
     * @return ItemManager
     */
    public function makeItemManager($itemManagerFields = [])
    {
        /** @var ItemManagerRepository $itemManagerRepo */
        $itemManagerRepo = App::make(ItemManagerRepository::class);
        $theme = $this->fakeItemManagerData($itemManagerFields);
        return $itemManagerRepo->create($theme);
    }

    /**
     * Get fake instance of ItemManager
     *
     * @param array $itemManagerFields
     * @return ItemManager
     */
    public function fakeItemManager($itemManagerFields = [])
    {
        return new ItemManager($this->fakeItemManagerData($itemManagerFields));
    }

    /**
     * Get fake data of ItemManager
     *
     * @param array $postFields
     * @return array
     */
    public function fakeItemManagerData($itemManagerFields = [])
    {
        $fake = Faker::create();

        return array_merge([
            'item_id' => $fake->randomDigitNotNull,
            'wechat_user_id' => $fake->randomDigitNotNull,
            'status' => $fake->randomDigitNotNull,
            'updated_at' => $fake->word,
            'created_at' => $fake->word
        ], $itemManagerFields);
    }
}
